package com.smsc.headend.task.engine.service.report.impl;

import cn.hutool.core.date.SystemClock;
import com.smsc.headend.module.report.entity.LogSyncTimeHis;
import com.smsc.headend.module.task.enums.TaskType;
import com.smsc.headend.task.engine.mapper.LogSyncTimeHisMapper;
import com.smsc.headend.task.engine.service.report.TimeSyncReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liangli
 * @date 2020/10/28
 */
@Service
@Slf4j
public class TimeSyncReportServiceImpl implements TimeSyncReportService {
    @Autowired
    LogSyncTimeHisMapper logSyncTimeHisMapper;

    @Override
    public void saveReport(Long deviceId, Long deviceType, Long syncTime, Integer syncResult, Long deviceTime, Long serverTime, Long timeDiffBefore, Long timeDiffAfter, Long userId, Integer syncSrc) {
        log.debug("save timeSyncReport: meterId={} ,syncResult={} ,userId={}", deviceId, syncResult, userId);
        LogSyncTimeHis logSyncTimeHis = new LogSyncTimeHis();
        logSyncTimeHis.setDeviceId(deviceId);
        logSyncTimeHis.setDeviceType(deviceType == null ? null : deviceType.intValue());
        logSyncTimeHis.setTvSync(syncTime);
        logSyncTimeHis.setTvDevice(deviceTime);
        logSyncTimeHis.setTvServer(serverTime);
        logSyncTimeHis.setDiffSecondBefore(timeDiffBefore);
        logSyncTimeHis.setDiffSecondAfter(timeDiffAfter);
        logSyncTimeHis.setSyncResult(syncResult);
        logSyncTimeHis.setUserId(userId);
        logSyncTimeHis.setTvUpdate(SystemClock.now() / 1000);
        logSyncTimeHis.setSyncSrc(syncSrc);
        logSyncTimeHisMapper.insert(logSyncTimeHis);
    }
}
